# -*- coding: utf-8 -*-

import psycopg2

conn = psycopg2.connect('host=localhost port=5432 user=postgres password=123456 dbname=Vancouver')

cur = conn.cursor()

cur.execute("SELECT ST_AsTIFF(rast, 'LZW') AS rasttiff FROM test WHERE rid=1;")

rasttiff = cur.fetchone()

print("获得返回值，开始导出")

if rasttiff is not None:
    open('D:/tiff/t/test.tif', 'wb').write(rasttiff[0])

cur.close()
conn.close()